$(document).ready(function() {
	$(".pam-follow").click(function(evt) {
		evt.preventDefault();
		var follow = $(this);
		var unfollow = $(this).parent().find(".pam-unfollow");
		$.ajax({
			url : follow.attr("href"),
			dataType : 'json',
			success : function(data) {
				var msg = data['error'];
				if (msg == "") {
					follow.hide();
					unfollow.show();
					return;
				}
				else {
					alert(msg);
				}
			},
			error : function(xhr, testStatus, error) {
				alert("Communication error!");
				return;
			}
		});
	});
	
	$(".pam-unfollow").click(function(evt) {
		evt.preventDefault();
		var unfollow = $(this);
		var follow = $(this).parent().find(".pam-follow");
		$.ajax({
			url : unfollow.attr("href"),
			dataType : 'json',
			success : function(data) {
				var msg = data['error'];
				if (msg == "") {
					unfollow.hide();
					follow.show();
					return;
				}
				else {
					alert(msg);
				}
			},
			error : function(xhr, testStatus, error) {
				alert("Communication error!");
				return;
			}
		});
	});
	
});